package com.cuit.riskassessment.action.rc;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cuit.riskassessment.service.RcService;
import com.cuit.riskassessment.util.Result;
import com.cuit.riskassessment.vo.RCParam;

/**
 * 处理Rc中相关的请求
 * @author Yang_Zhiqin-pc
 *
 */
@Controller
@RequestMapping(value="rc")
public class RcAction {
 
	@Autowired
	@Resource(name="rcService")
	private RcService rcService;
	
	@RequestMapping(value="addorupdate")
	public @ResponseBody Object addOrUpdate(HttpServletResponse res, RCParam rc)
	{
		
		res.setHeader("Accept",  "application/json");
		Result result = new Result();
		result.setMessage("添加成功！");
		result.setSuccess(true);
		
		if(!this.rcService.updateOrAdd(rc))
		{
			result.setSuccess(false);
			result.setMessage("添加失败！");
		}
		return result;
	}
	
	
	@RequestMapping(value="get")
	public @ResponseBody Object getRc(HttpServletResponse res, @RequestParam(value="projid")int projid)
	{
		res.setHeader("Accept",  "application/json");
		Result result = new Result();
		Object obj = this.rcService.getRc(projid);
		if(obj == null)
		{
			result.setSuccess(false);
		}else
		{
			result.setSuccess(true);
			result.setOthers(obj);
		}
		
		return result;
	}
	
}
